package com.test.huffmanserver.controller;


import com.test.huffmanserver.dto.HuffmanDto;
import com.test.huffmanserver.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;


@RestController
@CrossOrigin
public class FileController {

    @Autowired
    private FileService fileService;

    @Autowired
    HttpServletResponse response;


    @PostMapping("/zipString")
    public HuffmanDto zipString(@RequestBody HashMap<String,String> map){
        return fileService.zipString(map.get("str"));
    }

    @PostMapping("/zipFile")
    public HuffmanDto zipFile(@RequestParam("file") MultipartFile file){
        return fileService.zipFile(file);
    }

    @PostMapping("/unZipString")
    public String unZipString(@RequestBody HuffmanDto dto){
        return fileService.unZipString(dto);
    }

    @PostMapping("/unZipFile")
    public ResponseEntity<byte[]> fileProcess(@RequestParam("file") MultipartFile file){
        return fileService.unZipFile(file);
    }

    @PostMapping("/zipDownload")
    public ResponseEntity<byte[]> downloadFile(@RequestParam("file") MultipartFile file){
        return fileService.zipDownload(file);
    }



}